Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Masthead): Update subcomponent names #729

Merged
merged 8 commits into from
Aug 13, 2024

Conversation

wise-king-sullyman
Copy link
Collaborator

Towards #718

Copy link
Contributor

@adamviktora adamviktora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great!

I like the new helpers and the way they are structured + their description, it is a good starting point for refactoring the other helpers too.

Some comments / questions bellow

import { JSXOpeningElement, JSXMemberExpression } from "estree-jsx";

/** Gets the name of an opening element or member expression */
export function getNodeName(node: JSXOpeningElement | JSXMemberExpression) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function getNodeName(node: JSXOpeningElement | JSXMemberExpression) {
export function getNodeName(node: JSXOpeningElement) {

I'd rather separate the JSXMemberExpression handling into a separate function. Because if I am not mistaken, getNodeName will be called from the outside only with a node of type JSXOpeningElement, but when calling it recursively from the inside, we always pass a JSXMemberExpression node.

We can have it as a private function in this file I think.

function getJSXMemberExpressionName(node: JSXMemberExpression) {
  switch (node.object.type) {
    case "JSXMemberExpression":
      return getJSXMemberExpressionName(node.object);
    case "JSXIdentifier":
      return node.object.name;
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my idea with just naming this helper getNodeName was that over time we would expand it for resolving the name of nodes of various types.

I'm not against splitting the logic into discrete private functions and minimizing recursion to help improve readability at all though 🙂

CC @thatblindgeye since you left a comment about this same kind of stuff.

// dist imports
{
code: `import { MastheadBrand } from '@patternfly/react-core/dist/esm/components/Masthead/MastheadBrand'; <MastheadBrand />`,
output: `import { MastheadLogo } from '@patternfly/react-core/dist/esm/components/Masthead/MastheadBrand'; <MastheadLogo data-codemods />`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the import path be changed to .../Masthead/MastheadLogo ? I am not sure about this, just asking.

@@ -0,0 +1,18 @@
### masthead-name-changes [(#10809)](https://github.com/patternfly/patternfly-react/pull/10809)

The old `MastheadBrand` component has been renamed to `MastheadLogo`, and the old `MastheadMain` has been renamed to `MastheadBrand`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the message might be confusing for some consumers (or at least the messages given in the codemod output "MastheadMain has been renamed to MastheadBrand"), I like using the word "old" here, which makes more sense.

I was confused at the first place why are we renaming these components, when they will still stay in the new Masthead.

Maybe we can add a sentence here, like "MastheadMain will now wrap both MastheadToggle and MastheadBrand within itself.".

I know there will probably be a second codemod for wrapping the components in MastheadMain and the message there will better describe the whole change, but still this renaming which is not really renaming might be confusing (but probably not many consumers read the messages, I guess they just run the fix, so I am ok with keeping it as is).

import { ImportDefaultSpecifierWithParent } from "./interfaces";

/** Gets the import path string for a default import */
export function getDeclarationString(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a nit so not a blocker, but would getDefaultDeclarationString or something similar be more accurate?

import { JSXOpeningElement, JSXMemberExpression } from "estree-jsx";

/** Gets the name of an opening element or member expression */
export function getNodeName(node: JSXOpeningElement | JSXMemberExpression) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going off of Adam's comment above, another nit so not a blocker but if this helper is meant solely for these 2 scenarios, might be worth updating the name to reflect that (if we can without it become tooooo verbose).

import { getAttributeName } from "./getAttributeName";

/** Returns true if the passed opening element has a data-codemods attribute */
export function hasCodeModDataTag(openingElement: JSXOpeningElement) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could always be a separate helper, but just wondering if we should only check if the data tag exists by name, or return the actual attribute and base conditional logic on that. Just thinking if we ever start supplying specific values to a data-codemods attribute, e.g. maybe we only want to skip/run a rule if an openingElement has data-codemods="renamed", but not data-codemods="deprecated" or something.

Copy link
Collaborator

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment below. I'm good with the getNodeName helper name based on your explanation above.

@@ -0,0 +1,7 @@
import { MastheadLogo, MastheadBrand } from "@patternfly/react-core";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output just needs to be re-updated, looks like it's still using the fixed output from when you were also updating MastheadMain to MastheadBrand

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops

Copy link
Contributor

@adamviktora adamviktora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


if (shouldRenameNode) {
fixes.push(fixer.replaceText(node.name, newName));
fixes.push(fixer.insertTextAfter(node.name, " data-codemods"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be optional, I know we need the data-codemods for the followup Masthead rule, but in other cases it may be an unnecessary addition.

But if anything, it can be done as a followup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I went back and forth on that and IIRC talked it over with @thatblindgeye, I think we landed on always adding it to prevent issues and adding #723 so that we aren't leaving consumer codebases littered with our data tags.

I'm not super opposed to making it optional though, but yeah would want to do it as a followup.

@thatblindgeye thatblindgeye merged commit 23a8d8d into patternfly:main Aug 13, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants